<?php include_once("connection.php"); // the connection to the database ?>
<?php if(!$_GET['submitted']) { ?>
	<div style="overflow:hidden; margin:1em;">
		<h2>Are you sure that you want to delete "<?php echo $_GET['category_name'] ?>" and the relative branch?</h2>
		<a href="delete.php?category_id=<?php echo $_GET['category_id'] ?>&category_name=<?php echo $_GET['category_name'] ?>&submitted=true" class="nyroModal">[ <?php echo YES; ?> ]</a>
		<a href="#" onclick="$.nyroModalRemove();">[ <?php echo NO; ?> ]</a>
	</div>
<?php } else { 
	// recursive delete function
	function cascadeDelete($category_id, $conn) {
		$relatedCategory =  mysql_query("SELECT category_id FROM category WHERE parent_id = ".$category_id) or die(mysql_error());
		mysql_query("DELETE FROM category WHERE category_id = ".$category_id) or die(mysql_error());
		while ($row = mysql_fetch_assoc($relatedCategory)) {
			$this_id =  $row["category_id"];
			cascadeDelete($this_id, $conn);
			$relatedCategory->MoveNext();
		}
	}
	cascadeDelete($_GET['category_id'],$conn);
	?>
	<div style="overflow:hidden; margin:1em;">
		<h1>Branch deleted!</h1>
		<a href="#" onclick="$.nyroModalRemove();">Close</a>
	</div>
<?php } ?>